package com.xjj.serviceattend.consumer;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.xjj.entity.Attend;
import com.xjj.serviceattend.service.AttendService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Auther: AYang
 * @Date: 2022/10/26 15:02
 * @Description:
 */
@Component
public class MyConsumer {
    @Autowired
    AttendService attendService;

    @RabbitListener(queues = "queueAttendDlx")
    public void receiveAttendDlx(Attend attend, Message message, Channel channel) throws IOException {
        if (attend.getDate().equals(attendService.getDateByDate(attend.getDate()))){
            // 更新日期一致，更新数据
            attendService.updateByCondition(attend);
        }else {
            // 更新日期不一致，添加考勤数据
            attendService.addRecord(attend);
            System.out.println("attend:"+attend);
            System.out.println("message:"+message);
            System.out.println("channel"+channel);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
            System.out.println("------------处理添加考勤");
        }

    }
}
